<?php
	/*
		$q = new QueryHelper('localhost', '', '');
		$r = $q->query("SELECT * FROM Table1");
		$q->close();
		//
		$q->setUser('root');
		$q->updateConnection();
		$r = $q->query("SELECT * FROM Table2");
		$q->close();
	*/
	class QueryHelper
	{
		private $con;
		private $dom;
		private $usr;
		private $pass;
		public function __construct($domain, 
									$user, 
									$password)
		{
			$this->setDomain($domain);
			$this->setUser($user);
			$this->setPassword($password);
			$this->updateConnection();
		}
		public function setDomain($value)
		{
			$this->dom = $value;
		}
		public function getDomain()
		{
			return $this->dom;
		}
		public function setUser($value)
		{
			$this->usr = $value;
		}
		public function getUser()
		{
			return $this->usr;
		}
		public function setPassword($value)
		{
			$this->pass = $value;
		}
		public function getPassword()
		{
			return $this->pass;
		}
		private function updateConnection()
		{
			$this->con = mysql_connect($this->getDomain(), 
										$this->getUser(), 
										$this->getPassword());
			if(!$con)
			{
				die("Error on connect: mysql_error()");
			}
		}
		public function getConnection()
		{
			return $this->con;
		}
		public function run($query)
		{
			return mysql_query($query, $this->con) 
			or die("Error on query: mysql_error()");
		}
		public function close()
		{
			mysql_close($this->con);
		}
	}
?>